import { OrderPayStatusEnum, OrderStateEnum, RefundStatusEnum } from '@/enums/orderEnums'

/**
 * 活动订单状态
 */
export const ActivityOrderStatusEnum = {
    /** 已退款 */
    REFUNDED: {
        color: '#F53F3F',
        name: '已退款',
        value: 0
    },
    /** 退款中 */
    REFUNDING: {
        color: '#F53F3F',
        name: '退款中',
        value: 1
    },
    /** 部分退款 */
    PART_REFUND: {
        color: '#F53F3F',
        name: '部分退款',
        value: 2
    },
    /**  */
    REFUND_FAILED: {
        color: '#F53F3F',
        name: '退款失败',
        value: 4
    },
    /**待付款 */
    WAIT_PAY: {
        color: '#165DFF',
        name: '待付款',
        value: 5
    },
    /**已付款 */
    PAYMENT: {
        color: '#165DFF',
        name: '已付款',
        value: 6
    },
    PAY_FAIL: {
        color: '#F53F3F',
        name: '支付失败',
        value: 6
    },
    OTHOR: {
        name: '-',
        value: 100,
        color: '#165DFF',
    }
}

/**
 * 查询活动订单状态
 * @param {*} orderState 订单状态
 * @param {*} payState 支付状态
 * @param {*} refundStatus 退款状态
 * @returns 
 */
export function getActivityOrderStatus(orderState, payState, refundStatus) {
    if (orderState === OrderStateEnum.WAIT) return ActivityOrderStatusEnum.WAIT_PAY
    if (payState === OrderPayStatusEnum.CLOSE || payState === OrderPayStatusEnum.FAIL) return ActivityOrderStatusEnum.PAY_FAIL

    // 订单关闭
    if (orderState === OrderStateEnum.CLOSE && payState === OrderPayStatusEnum.SUCCESS) {
        if (refundStatus === RefundStatusEnum.UNREFUNDED) return ActivityOrderStatusEnum.REFUNDING
        if (refundStatus === RefundStatusEnum.REFUNDED) return ActivityOrderStatusEnum.REFUNDED
        if (refundStatus === RefundStatusEnum.REFUNDING) return ActivityOrderStatusEnum.REFUNDING
        if (refundStatus === RefundStatusEnum.PART_REFUND) return ActivityOrderStatusEnum.PART_REFUND
        if (refundStatus === RefundStatusEnum.REFUND_FAILED) return ActivityOrderStatusEnum.REFUND_FAILED
    }
    if (orderState === OrderStateEnum.DONE && payState === OrderPayStatusEnum.SUCCESS) return ActivityOrderStatusEnum.PAYMENT
    return ActivityOrderStatusEnum.OTHOR;
}


/**
 * 查询子订单退款状态
 * @param {*} orderState 订单状态
 * @param {*} subRefundStatus 退款状态
 * @returns 
 */
export function getActivitySubOrderStatus(orderState, payState, subRefundStatus) {
    if (orderState === ActivityOrderStatusEnum.WAIT_PAY.value) return ActivityOrderStatusEnum.WAIT_PAY
    if (payState === OrderPayStatusEnum.SUCCESS) {
        switch (subRefundStatus) {
            case RefundStatusEnum.REFUNDED:
                return ActivityOrderStatusEnum.REFUNDED;
            case RefundStatusEnum.REFUNDING:
                return ActivityOrderStatusEnum.REFUNDING;
            case RefundStatusEnum.REFUND_FAILED:
                return ActivityOrderStatusEnum.REFUND_FAILED;
            case RefundStatusEnum.PART_REFUND:
                return ActivityOrderStatusEnum.PART_REFUND;
            default:
                return ActivityOrderStatusEnum.PAYMENT;
        }
    }

    return ActivityOrderStatusEnum.OTHOR;
}